package com.xcl.controller;

import com.xcl.service.XclTailAfterServiceInter;
import com.zzg.entity.Tailafter;
import com.zzg.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName XclTailAfterController
 * @Description 新增跟踪控制器层
 * @Author: xiaochaolei
 * @date 2021/7/13 15:04
 * @Version 1. 0
 */
@Controller
public class XclTailAfterController {
    @Autowired
    XclTailAfterServiceInter xclTailAfterServiceInter;


    /**
     * 查询以及多条件查询
     * @param page 页码数
     * @param limit 条目数
     * @param id 是否是多条件查询
     * @param waybill_id 运单id
     * @param state 跟踪状态
     * @param startDate 起止日期
     * @param endingDate 结束日期
     * @return
     */
    @GetMapping(value = "/XclTailAfterControllerGetXclTailAfterAll", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getXclTailAfterAll(int page, int limit,String id,String waybill_id,String state,String startDate,String endingDate) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", "0");
        map.put("msg", "0");
        if (id==null){
            map.put("count",xclTailAfterServiceInter.getXclTailAfterAll().size());
            map.put("data",xclTailAfterServiceInter.getXclTailAfterBYLimit(page,limit));
            return map;
        }else {
            map.put("count",xclTailAfterServiceInter.getXclTailAfterBYCondition(page,limit,waybill_id,startDate,endingDate,state).size());
            map.put("data",xclTailAfterServiceInter.getXclTailAfterBYCondition(page,limit,waybill_id,startDate,endingDate,state));
            return map;
        }
    }

    /**
     * 根据id删除跟踪信息
     * @param id 跟踪id
     * @return 是否成功
     */
    @PostMapping(value = "/XclTailAfterControllerDeleteXclTailAfter", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String deleteXclTailAfter(String id){
        if (xclTailAfterServiceInter.deleteXclTailAfter(id)>0){
            return "成功";
        }
        return "失败";
    }

    /**
     * 新增跟踪信息
     * @param tailafter 跟踪信息
     * @return 是否成功
     */
    @PostMapping(value = "/XclTailAfterControllerInsertXclTailAfter", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String insertXclTailAfter(Tailafter tailafter){
        //设置id
        tailafter.setTailafter(UuidUtil.getUuid());
        //判断是否新增成功
        if ( xclTailAfterServiceInter.insertXclTailAfter(tailafter)>0){
            return "成功";
        }
        return "失败";
    }

    /**
     * 根据id查询跟踪信息
     * @param id 跟踪id
     * @return 跟踪信息
     */
    @PostMapping(value = "/XclTailAfterControllerGetTailafterByTailAfter", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Tailafter getTailafterByTailAfter(String id){
        Tailafter tailafterByTailAfter = xclTailAfterServiceInter.getTailafterByTailAfter(id);
        return tailafterByTailAfter;
    }

    /**
     * 修改跟踪信息
     * @param tailafter 跟踪信息
     * @return 是否成功
     */
    @PostMapping(value = "/XclTailAfterControllerUpdateTailafter", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String updateTailafter(Tailafter tailafter){
      if (xclTailAfterServiceInter.updateTailafter(tailafter)>0){
          return "成功";
      }
        return "失败";
    }


 }
